<%--
  Created by IntelliJ IDEA.
  User: LnDamowang
  Date: 2019-01-04
  Time: 17:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>油箱列表</title>
    <jsp:include page="${pageContext.request.contextPath}/common/common.jsp"/>
    <script>
        //初始化
        $(function () {
            $("#tankTable").bootstrapTable({
                onLoadSuccess:function(data){
                    var elems = Array.prototype.slice.call(document.querySelectorAll('.abc'));
                    elems.forEach(function(html) {
                        var switchery = new Switchery(html);
                    });
                },
                url:'${pageContext.request.contextPath}/tank/queryAll',
                // height:300,
                pagination:true,
                pageSize:5,
                pageList:[5,10,15],
                clickToSelect:true,
                columns:[
                    {
                        checkbox:true
                    },
                    {
                        field:'tankName',
                        title:'油箱名称'
                    },

                    {
                        field:'state',
                        title:'状态',
                        formatter:function (a,b,c) {
                            if (b.state==1){
                                return "<input disabled checked type='checkbox' class='abc js-switch'/>" ;
                            }
                            else{
                                return "<input disabled type='checkbox' class='abc js-switch'/>" ;
                            }
                        }
                    },
                    {
                        field:'oil.oilName',
                        title:'油品'
                    },
                    {
                        field:'oil.price',
                        title:'进油价格（元）'
                    },
                    {
                        field:'con.conversionOf',
                        title:'出售价格（元）'
                    },
                    {
                        field:'oil.kucun',
                        title:'库存（升）'
                    },
                    {
                        field:'oil.remind',
                        title:'报警库存（升）'
                    },
                    {
                        field:'detail',
                        title:'备注'
                    },
                    {
                        title:'操作',
                        formatter:function(value,row,index){
                            if(row.state==1){
                                return "<button class='btn  btn-primary' onclick='xunjian("+row.id+")'><span class='glyphicon glyphicon-edit'></span>&nbsp;巡检</button>"
                            }
                            if(row.state==0) {
                                return "<button class='btn  btn-primary' onclick='weixiu("+row.id+")'><span class='glyphiconglyphicon-edit'></span>&nbsp;维修</button>"
                            }
                            if(row.state==2) {
                                return "<button class='btn  btn-primary' onclick='weixiu("+row.id+")'><span class='glyphiconglyphicon-edit'></span>&nbsp;启用</button>"
                            }

                        }
                    }
                ]
            });
        });
        function xunjian(id) {
            $("input[name='tankId']").val(id);
            $("input[name='id']").val(id);
            <!--时间日历-->
            $('#datetimepicker1').datetimepicker({
                format: 'YYYY-MM-DD',
                locale: moment.locale('zh-cn')
            });
            $("#stateModel").modal("show");
        }
        function doxunjian() {
            var formStr = $('#stateform').serialize();
            //处理表单控件的中文乱码
            params = decodeURIComponent(formStr, true);
            alert(params);
            $.ajax({
                'url':"${pageContext.request.contextPath}/tankMain/updateState",
                'type':'post',
                'data':params,
                success:function (date) {
                    alert(date)
                    $("#tankTable").bootstrapTable('load',date);
                    var elems = Array.prototype.slice.call(document.querySelectorAll('.abc'));
                    elems.forEach(function(html) {
                        var switchery = new Switchery(html);
                    });
                    $("#stateModel").modal("hide");
                }
            });
        }

        function weixiu(id) {
            $("input[name='id']").val(id);
            $("#weixiu").modal("show");
        }
        function doweixiu() {
            var id = $("input[name='id']").val();
            var detail = $("input[name='detail']").val();
            alert(detail)
            <%--$.post("${pageContext.request.contextPath}/tank/weixiu",{"id":id,"detail":detail},function (date) {--%>
                <%--alert(date)--%>
            <%--})--%>
        }
    </script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">油箱列表</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-6">
                <button onclick="toadd()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="tankTable"></table>
            </div>
        </div>
    </div>
</div>

<%--状态模块--%>
<div class="modal fade" id="stateModel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">状态</h4>
            </div>
            <div class="modal-body">
                <form action="" class="form-horizontal" id="stateform">
                    <input type="hidden" name="tankId">
                    <input type="hidden" name="id">
                    <input type="hidden" name="admin" value="1">
                    <div class="form-group">
                        <label class="col-sm-3 text-right control-label" for="">损坏原因：</label>
                        <div class="col-sm-8">
                            <select name="state" id="" class="form-control">
                                <option value="">**请选择**</option>
                                <option value="2">停用</option>
                                <option value="0">损坏</option>
                                <option value="0">其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 text-right  control-label" for="detail">备注:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="detail" name="detail"  placeholder="备注" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 text-right">时间</label>
                        <div class="col-sm-8">
                            <div class="input-group" id="datetimepicker1">
                                <input name="date" type='text' class="form-control" />
                                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="doxunjian()">修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<%--维修--%>
<div class="modal fade" id="weixiu">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">维修</h4>
            </div>
            <div class="modal-body">
                <form action="" class="form-horizontal" id="weixiuform">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 text-right  control-label" for="detail">备注:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="detail" name="detail"  placeholder="备注" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" onclick="doweixiu()" class="btn btn-primary">确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>
